package io.adrainty.bolee.task.stream;

import io.adrainty.bolee.file.feign.IFileBusinessFeign;
import io.adrainty.bolee.file.models.entity.FileEntity;
import io.adrainty.bolee.framework.commons.basic.ResultDTO;
import io.adrainty.bolee.framework.commons.utils.JsonUtil;
import io.adrainty.bolee.framework.commons.utils.ResultDTOUtil;
import io.adrainty.bolee.framework.mq.basic.MQMessage;
import io.adrainty.bolee.framework.mq.basic.MQMessageType;
import io.adrainty.bolee.framework.mq.stream.BaseStreamHandler;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * <p>FileMsgConsumer</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description FileMsgConsumer
 * @since 2025/8/18 15:17:26
 */

@Component(value = "fileChannel")
public class FileMsgConsumer extends BaseStreamHandler {

    @Resource
    private IFileBusinessFeign fileBusinessFeign;

    @Override
    public void doConsume(MQMessage message) {
        String content = message.getContent();
        FileEntity file = JsonUtil.fromJson(content, FileEntity.class);
        ResultDTO<Boolean> resultDTO = fileBusinessFeign.clearFile(file.getId());
        ResultDTOUtil.assertResultSuccess(resultDTO);
    }

    @Override
    public MQMessageType acceptMsgType() {
        return MQMessageType.FILE_MESSAGE;
    }

}
